import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mes_app/common/index.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

import 'index.dart';

class WoreportworkIndexPage extends GetView<WoreportworkIndexController> {
  const WoreportworkIndexPage({super.key});

  // 列表
  Widget _buildList() {
    return ListView.separated(
      itemBuilder: (context, index) {
        WoreportworkTaskListItemModel item = controller.items[index];
        return OrderCrad(
          headLeftWidget: TextWidget.h4(
            item.swocode!,
            scale: WidgetScale.small,
          ),
          contentWidget:const TextWidget.body("content")
        );
      },
      separatorBuilder: (context, index) {
        return SizedBox(height: AppSpace.listRow * 2);
      },
      itemCount: controller.items.length,
    );
  }

  // 主视图
  Widget _buildView() {
    return _buildList();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<WoreportworkIndexController>(
      init: WoreportworkIndexController(),
      id: "woreportwork_index",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: Text(LocaleKeys.woreportworkIndexTitle.tr)),
          body: SmartRefresher(
            controller: controller.refreshController, // 刷新控制器
            enablePullUp: true, // 启用上拉加载
            onRefresh: controller.onRefresh, // 下拉刷新回调
            onLoading: controller.onLoading, // 上拉加载回调
            footer: const SmartRefresherFooterWidget(), // 底部加载更多组件
            child: _buildView(),
          ).paddingAll(AppSpace.page),
        );
      },
    );
  }
}
